var CharacterCounter = function(config) {
	ClientAction.call(this, config);
}

CharacterCounter.prototype.execute = function() {
	ClientAction.prototype.execute.call(this);

	var textBoxControlId = this._config.OwnerID + '_' + this._config.TextField;
	var textBoxControl = UIControl.getControl(textBoxControlId);
	this.textBoxControl = textBoxControl;
	var extTextBoxElement = textBoxControl._control.getEl();

	var labelControlId = this._config.OwnerID + '_' + this._config.LabelName;
	var labelControl = UIControl.getControl(labelControlId);
	this.labelControl = labelControl;

	extTextBoxElement.on("keyup", this.keyUpHandler, this);
}

CharacterCounter.prototype.keyUpHandler = function() {
	var caracters = this.textBoxControl.getValue().length;
	var SMS = 1;
	if (caracters > 160) {
		var dif = (caracters - 160);
		var newSMS = Math.floor(dif / 153);
		if (dif % 153 != 0) {
			SMS += (newSMS + 1);
		} else {
			SMS += newSMS;
		}
	}

	if (this.labelControl) {
		if (caracters <= 772) {
			this.labelControl.setText("Broj karaktera: " + caracters
					+ " (broj poruka " + SMS + ")");
		} else {
			var maxText = this.textBoxControl.getValue().substring(0, 772);
			this.textBoxControl.setValue(maxText);
		}
	}
}

var ChangeControlText = function(config) {
	ClientAction.call(this, config);
}

ChangeControlText.prototype.execute = function() {
	ClientAction.prototype.execute.call(this);
	var controlId = this._config.OwnerID + '_' + this._config.ControlName;
	var control = UIControl.getControl(controlId);
	control._control.setText(this._config.Text);
}

var ChangeControlVisibility = function(config) {
	ClientAction.call(this, config);
}

ChangeControlVisibility.prototype.execute = function() {
	ClientAction.prototype.execute.call(this);
	var controlId = this._config.OwnerID + '_' + this._config.ControlName;
	var control = UIControl.getControl(controlId);
	control._control.setVisible(this._config.Visible);
}

var ChangeControlCollapsible = function(config) {
	ClientAction.call(this, config);
}

ChangeControlCollapsible.prototype.execute = function() {
	ClientAction.prototype.execute.call(this);
	var controlId = this._config.OwnerID + '_' + this._config.ControlName;
	var control = UIControl.getControl(controlId);
	
	if (this._config.Collapse) {
		control._control.collapse();
	} else {
		control._control.expand();
	}
}